<?php
/*
	MyHosting by KuJoe <www.jmd.cc>
	A plugin to allow cPanel based web hosting over MyBB 1.6
*/

if (! defined('IN_MYBB')) {
	die('Nope.');
}

$plugins->add_hook("admin_config_menu","myhosting_adminnav");
$plugins->add_hook("admin_tools_menu_logs", "myhosting_lognav");
$plugins->add_hook("admin_config_action_handler", "myhosting_adminact");
$plugins->add_hook("admin_tools_action_handler", "myhosting_logact");
$plugins->add_hook("admin_config_permissions", "myhosting_adminperm");
$plugins->add_hook("admin_tools_permissions", "myhosting_logperm");
$plugins->add_hook("admin_load", "myhosting_admin");
$plugins->add_hook("admin_load", "myhosting_logs");
$plugins->add_hook("datahandler_user_validate","myhosting_validate_user");

function myhosting_validate_user($datahandler) {
	global $lang;
	$lang->load("myhosting");
	$usrfc = substr($datahandler->data['username'], 0, 1);	
	if (is_numeric($usrfc)) {
		$datahandler->set_error($lang->myhosting_number_username);
		return false;
    }
    
    return true;
}

function myhosting_info() {
	return array(
		'name'			=> 'MyHosting',
		'description'		=> 'A cPanel hosting system for MyBB 1.6',
		'website'		=> 'http://mods.mybboard.net',
		'author'		=> 'KuJoe',
		'authorsite'		=> 'http://www.jmd.cc',
		'version'		=> '0.1',
		'compatibility'		=> '16*',
		'guid'			=> '',
		'sysname'		=> 'myhosting',
	);
}

function myhosting_activate() {
	global $db;

	$myhosting_group = array(
		'name'			=> 'myhosting',
		'title'			=> 'MyHosting',
		'description'		=> 'MyHosting Settings.',
		'disporder'		=> '99',
		'isdefault'		=> 'no'
	);

	$db->insert_query('settinggroups', $myhosting_group);
	$gid = $db->insert_id();

	$myhosting_setting_1 = array(
		'name'			=> 'myhosting_onoff',
		'title'			=> 'MyHosting Status',
		'description'		=> 'Is MyHosting online or offline?',
		'optionscode'		=> 'onoff',
		'value'			=> '0',
		'disporder'		=> 0,
		'gid'			=> intval($gid),
	);

	$myhosting_setting_2 = array(
		'name'			=> 'myhosting_groups',
		'title'			=> 'Allowed Usersgroups',
		'description'		=> 'Usergroup IDs that are allowed to use MyHosting (Comma seperated).',
		'optionscode'		=> 'text',
		'value'			=> '3,4,6',
		'disporder'		=> 3,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_3 = array(
		'name'			=> 'myhosting_modgroups',
		'title'			=> 'Staff Usersgroups',
		'description'		=> 'Usergroup IDs that are allowed to administrate MyHosting (Comma seperated).',
		'optionscode'		=> 'text',
		'value'			=> '3,4,6',
		'disporder'		=> 3,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_4 = array(
		'name'			=> 'myhosting_hostname',
		'title'			=> 'Server hostname/IP',
		'description'		=> 'Enter the hostname or IP address for your WHM server.',
		'optionscode'		=> 'text',
		'value'			=> '',
		'disporder'		=> 4,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_5 = array(
		'name'			=> 'myhosting_whmuser',
		'title'			=> 'WHM Username',
		'description'		=> 'Enter the username for your WHM server.',
		'optionscode'		=> 'text',
		'value'			=> '',
		'disporder'		=> 5,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_6 = array(
		'name'			=> 'myhosting_whmkey',
		'title'			=> 'WHM Remote Access Key',
		'description'		=> 'Enter the Remote Access Key for your WHM server.',
		'optionscode'		=> 'textarea',
		'value'			=> '',
		'disporder'		=> 6,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_7 = array(
		'name'			=> 'myhosting_subdom',
		'title'			=> 'Domain(s) for sub-domains (comma separated)',
		'description'		=> 'Provide a domain or domains that your clients will use for their sub-domain.',
		'optionscode'		=> 'text',
		'value'			=> 'yourdomain.com,yourdomain2.com,yourdomain2.com',
		'disporder'		=> 7,
		'gid'			=> intval($gid),
	);
	
	
	$myhosting_setting_8 = array(
		'name'			=> 'myhosting_pkg1',
		'title'			=> 'Plan 1',
		'description'		=> 'Name for your first hosting plan.',
		'optionscode'		=> 'text',
		'value'			=> 'Plan 1',
		'disporder'		=> 8,
		'gid'			=> intval($gid),
	);

	$myhosting_setting_9 = array(
		'name'			=> 'myhosting_pkg1bknd',
		'title'			=> 'Plan 1 Backend Name',
		'description'		=> 'This is what WHM knows Plan 1 as.',
		'optionscode'		=> 'text',
		'value'			=> 'plan1',
		'disporder'		=> 9,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_10 = array(
		'name'			=> 'myhosting_pkg1desc',
		'title'			=> 'Description for Plan 1',
		'description'		=> 'Provide some details about your first hosting plan.',
		'optionscode'		=> 'textarea',
		'value'			=> 'This is the Plan 1 description.',
		'disporder'		=> 10,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_11 = array(
		'name'			=> 'myhosting_pkg2',
		'title'			=> 'Plan 2',
		'description'		=> 'Name for your second hosting plan.',
		'optionscode'		=> 'text',
		'value'			=> 'Plan 2',
		'disporder'		=> 11,
		'gid'			=> intval($gid),
	);

	$myhosting_setting_12 = array(
		'name'			=> 'myhosting_pkg2bknd',
		'title'			=> 'Plan 2 Backend Name',
		'description'		=> 'This is what WHM knows Plan 2 as.',
		'optionscode'		=> 'text',
		'value'			=> 'plan2',
		'disporder'		=> 12,
		'gid'			=> intval($gid),
	);

	$myhosting_setting_13 = array(
		'name'			=> 'myhosting_pkg2desc',
		'title'			=> 'Description for Plan 2',
		'description'		=> 'Provide some details about your second hosting plan.',
		'optionscode'		=> 'textarea',
		'value'			=> 'This is the Plan 2 description.',
		'disporder'		=> 13,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_14 = array(
		'name'			=> 'myhosting_pkg3',
		'title'			=> 'Plan 3',
		'description'		=> 'Name for your third hosting plan.',
		'optionscode'		=> 'text',
		'value'			=> 'Plan 3',
		'disporder'		=> 14,
		'gid'			=> intval($gid),
	);

	$myhosting_setting_15 = array(
		'name'			=> 'myhosting_pkg3bknd',
		'title'			=> 'Plan 3 Backend Name',
		'description'		=> 'This is what WHM knows Plan 3 as.',
		'optionscode'		=> 'text',
		'value'			=> 'plan3',
		'disporder'		=> 15,
		'gid'			=> intval($gid),
	);	
	
	$myhosting_setting_16 = array(
		'name'			=> 'myhosting_pkg3desc',
		'title'			=> 'Description for Plan 3',
		'description'		=> 'Name for your third hosting plan.',
		'optionscode'		=> 'textarea',
		'value'			=> 'This is the Plan 3 description.',
		'disporder'		=> 16,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_17 = array(
		'name'			=> 'myhosting_tos',
		'title'			=> 'Terms of Service',
		'description'		=> 'The URL for your Terms of Service.',
		'optionscode'		=> 'text',
		'value'			=> 'http://www.mydomain.com/tos.location',
		'disporder'		=> 17,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_18 = array(
		'name'			=> 'myhosting_adminact',
		'title'			=> 'Automatic Activation',
		'description'		=> 'Turn off to require admin activation for all accounts.',
		'optionscode'		=> 'onoff',
		'value'			=> '0',
		'disporder'		=> 1,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_19 = array(
		'name'			=> 'myhosting_adminemail',
		'title'			=> 'Admin E-mail',
		'description'		=> 'E-mail to notify on new orders.',
		'optionscode'		=> 'text',
		'value'			=> 'my@email.com',
		'disporder'		=> 2,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_20 = array(
		'name'			=> 'myhosting_owndomains',
		'title'			=> 'Allow own domains?',
		'description'		=> 'Will you allow clients to register their own domains?',
		'optionscode'		=> 'onoff',
		'value'			=> '0',
		'disporder'		=> 7,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_21 = array(
		'name'			=> 'myhosting_ns1',
		'title'			=> 'Primary Nameserver',
		'description'		=> 'Primary Nameserver for clients with their own domain',
		'optionscode'		=> 'text',
		'value'			=> 'ns1.domain.com',
		'disporder'		=> 7,
		'gid'			=> intval($gid),
	);
	
	$myhosting_setting_22 = array(
		'name'			=> 'myhosting_ns2',
		'title'			=> 'Secondary Nameserver',
		'description'		=> 'Secondary Nameserver for clients with their own domain',
		'optionscode'		=> 'text',
		'value'			=> 'ns2.domain.com',
		'disporder'		=> 7,
		'gid'			=> intval($gid),
	);
	
	$myhosting_order = array(
		"tid"			=> NULL,
		"title"			=> 'myhosting_order',
		"template"		=> '<html>
<head>
<title>{$mybb->settings[bbname]} - {$title}</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<div align="center">
<form method="post" action="myhosting.php">
<table>
<tr>
<td>
<table border="1" style="border-collapse: collapse">
	<tr>
		<td>First Name:</td>
		<td><input type="text" name="fname" size="30" /></td>
	</tr>
	<tr>
		<td>Last Name:</td>
		<td><input type="text" name="lname" size="30" /></td>
	</tr>
	<tr>
		<td>State:</td>
		<td><input type="text" name="state" size="30" /></td>
	</tr>
	<tr>
		<td>Country:</td>
		<td><input type="text" name="country" size="30" /></td>
	</tr>
	<tr>
		<td>Domain:</td>
		<td>{$domainopts}</td>
	</tr>
</table>
</td>
</tr>
<tr>
<td width="100%">
{$myhpkgs1}
{$myhpkgs2}
{$myhpkgs3}
</td>
</tr>
<tr>
<td>
	<p align="center">
	<input type="checkbox" name="accepttos" id="accepttos" value="1"/>I have read and agree to the <a href="{$myhtos}" target="_blank">Terms of Service</a><strong><br>
	<input type="hidden" name="act" value="do_order">
	<input type="hidden" name="uid" value="{$mybb->user[uid]}">
	<input type="hidden" name="fusr" value="{$mybb->user[username]}">
	<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
	<input type="hidden" name="regip" value="{$myhip}" />
	<input class="button" name="send" type="submit" id="send" value="Sign Up" /></p>
</td>
</tr>
</table>
</form>
</div>
{$footer}
</body>
</html>',
		"sid"		=> "-1",
		"version"	=> "1.0",
		"dateline"	=> "0",
	);
	
	$myhosting_client = array(
		"tid"		=> NULL,
		"title"		=> 'myhosting_client',
		"template"	=> '<html>
<head>
<title>{$mybb->settings[bbname]} - {$title}</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<div align="center">
<table border="1" style="border-collapse: collapse">
	<tr>
		<td>First Name:</td>
		<td>{$myhostingfname}</td>
	</tr>
	<tr>
		<td>Last Name:</td>
		<td>{$myhostinglname}</td>
	</tr>
	<tr>
		<td>State:</td>
		<td>{$myhostingstate}</td>
	</tr>
	<tr>
		<td>Country:</td>
		<td>{$myhostingcountry}</td>
	</tr>
	<tr>
		<td>Domain:</td>
		<td>{$myhostingdomain}</td>
	</tr>
	<tr>
		<td>cPanel Username:</td>
		<td>{$myhostingusr}</td>
	</tr>
	<tr>
		<td>Package:</td>
		<td>{$myhostingpkg}</td>
	</tr>
	<tr>
		<td>Status:</td>
		<td>{$myhostingstatus}</td>
	</tr>
	<tr>
		<td>Cancellation:</td>
		<td>{$selfcancel}<br />
		<div id="cancelblk" style="display:none;text-align:center;width:300px;">
		<form method="post" action="myhosting.php">
		Reason (optional): <input type="text" name="rsn" size="30" value="" /><br />
		<input type="checkbox" name="cancelchk" value="understand" /> I understand that cancelling my hosting account cannot be reversed and I cannot create a new account until a staff member deletes my account from the database.<br />
		<input type="hidden" name="act" value="do_selfcancel">
		<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
		<input class="button" name="send" type="submit" id="send" value="Cancel my hosting account." />
		</div></td>
	</tr>
</table>
</div>
{$footer}
</body>
</html>',
		"sid"		=> "-1",
		"version"	=> "1.0",
		"dateline"	=> "0",
	);
	
	$myhosting_show = array(
		"tid"		=> NULL,
		"title"		=> 'myhosting_show',
		"template"	=> '<html>
<head>
<title>{$mybb->settings[bbname]} - {$title}</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<div align="center">
<form method="post" action="myhosting.php">
<table border="1" style="border-collapse: collapse">
	<tr>
		<td>First Name:</td>
		<td>
		<input type="text" name="fname" size="30" value="{$myhostingfname}" /></td>
	</tr>
	<tr>
		<td>Last Name:</td>
		<td>
		<input type="text" name="lname" size="30" value="{$myhostinglname}" /></td>
	</tr>
	<tr>
		<td>State:</td>
		<td>
		<input type="text" name="state" size="30" value="{$myhostingstate}" /></td>
	</tr>
	<tr>
		<td>Country:</td>
		<td>
		<input type="text" name="country" size="30" value="{$myhostingcountry}" /></td>
	</tr>
	<tr>
		<td>Domain:</td>
		<td>
		<input type="text" name="domain" size="30" value="{$myhostingdomain}" /></td>
	</tr>
	<tr>
		<td>cPanel Username:</td>
		<td>
		<input type="text" name="usr" size="30" value="{$myhostingusr}" /></td>
	</tr>
	<tr>
		<td>Package:</td>
		<td>{$myhostingpkg}</td>
	</tr>
	<tr>
		<td>Order IP:</td>
		<td><a href="http://whois.domaintools.com/{$myhostingregip}" target="_blank">{$myhostingregip}</a></td>
	</tr>
	<tr>
		<td>Secret Key:</td>
		<td>{$myhostingskey}</td>
	</tr>
	<tr>
		<td>Date:</td>
		<td>{$myhostingtime}</td>
	</tr>
	<tr>
		<td>Status:</td>
		<td>{$myhostingstatus}</td>
	</tr>
	<tr>
		<td colspan="2">
		<input type="hidden" name="act" value="do_save">
		<input type="hidden" name="suid" value="{$mybb->user[uid]}">
		<input type="hidden" name="shu" value="{$mybb->input[shu]}">
		<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
		<p align="center">
		<input class="button" name="send" type="submit" id="send" value="Save Client Information" /></td>
		</td>
	</tr>
</table>
</form>
</div>
{$footer}
</body>
</html>',
		"sid"		=> "-1",
		"version"	=> "1.0",
		"dateline"	=> "0",
	);
	
	$db->insert_query("templates", $myhosting_order);
	$db->insert_query("templates", $myhosting_client);
	$db->insert_query("templates", $myhosting_show);
	$db->insert_query('settings', $myhosting_setting_1);
	$db->insert_query('settings', $myhosting_setting_2);
	$db->insert_query('settings', $myhosting_setting_3);
	$db->insert_query('settings', $myhosting_setting_4);
	$db->insert_query('settings', $myhosting_setting_5);
	$db->insert_query('settings', $myhosting_setting_6);
	$db->insert_query('settings', $myhosting_setting_7);
	$db->insert_query('settings', $myhosting_setting_8);
	$db->insert_query('settings', $myhosting_setting_9);
	$db->insert_query('settings', $myhosting_setting_10);
	$db->insert_query('settings', $myhosting_setting_11);
	$db->insert_query('settings', $myhosting_setting_12);
	$db->insert_query('settings', $myhosting_setting_13);
	$db->insert_query('settings', $myhosting_setting_14);
	$db->insert_query('settings', $myhosting_setting_15);
	$db->insert_query('settings', $myhosting_setting_16);
	$db->insert_query('settings', $myhosting_setting_17);	
	$db->insert_query('settings', $myhosting_setting_18);
	$db->insert_query('settings', $myhosting_setting_19);
	$db->insert_query('settings', $myhosting_setting_20);
	$db->insert_query('settings', $myhosting_setting_21);
	$db->insert_query('settings', $myhosting_setting_22);
	
	rebuildsettings();
	
	$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."myhosting (
		`hid` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
		`uid` INT(10) NOT NULL ,
		`fusr` TEXT NOT NULL ,
		`fname` TEXT NOT NULL ,
		`lname` TEXT NOT NULL ,
		`state` TEXT NOT NULL ,
		`country` TEXT NOT NULL ,
		`domain` TEXT NOT NULL ,
		`usr` TEXT NOT NULL ,		
		`email` TEXT NOT NULL ,
		`pkg` INT(10) NOT NULL ,
		`regip` TEXT NOT NULL ,
		`skey` TEXT NOT NULL ,
		`status` INT(10) NOT NULL ,
		`time` TEXT NOT NULL,
		PRIMARY KEY (hid) 
		) TYPE = MYISAM ;"
	);

	$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."myhostinglogs (
		`logid` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
		`uid` INT(10) NOT NULL ,
		`time` TEXT NOT NULL,
		`msg` TEXT NOT NULL ,
		PRIMARY KEY (logid) 
		) TYPE = MYISAM ;"
	);

}

function myhosting_deactivate() {
	global $db;
	
	$db->query("DROP TABLE ".TABLE_PREFIX."myhosting");
	$db->query("DROP TABLE ".TABLE_PREFIX."myhostinglogs");
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title = 'myhosting_client'");
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title = 'myhosting_order'");
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title = 'myhosting_show'");
	$db->delete_query("settings","name='myhosting_onoff'");
	$db->delete_query("settings","name='myhosting_groups'");
	$db->delete_query("settings","name='myhosting_modgroups'");
	$db->delete_query("settings","name='myhosting_hostname'");
	$db->delete_query("settings","name='myhosting_whmuser'");
	$db->delete_query("settings","name='myhosting_whmkey'");
	$db->delete_query("settings","name='myhosting_subdom'");
	$db->delete_query("settings","name='myhosting_pkg1'");
	$db->delete_query("settings","name='myhosting_pkg1bknd'");
	$db->delete_query("settings","name='myhosting_pkg1desc'");
	$db->delete_query("settings","name='myhosting_pkg2'");
	$db->delete_query("settings","name='myhosting_pkg2bknd'");
	$db->delete_query("settings","name='myhosting_pkg2desc'");
	$db->delete_query("settings","name='myhosting_pkg3'");
	$db->delete_query("settings","name='myhosting_pkg3bknd'");
	$db->delete_query("settings","name='myhosting_pkg3desc'");
	$db->delete_query("settings","name='myhosting_tos'");
	$db->delete_query("settings","name='myhosting_adminact'");
	$db->delete_query("settings","name='myhosting_owndomains'");
	$db->delete_query("settings","name='myhosting_adminemail'");
	$db->delete_query("settings","name='myhosting_ns1'");
	$db->delete_query("settings","name='myhosting_ns2'");
	$db->delete_query("settinggroups","name='myhosting'");
	
	rebuild_settings();

}

function myhosting_lognav(&$sub_menu)
{
	global $mybb, $lang;
	$lang->load("myhosting", false, true);
		
	end($sub_menu);
	$key = (key($sub_menu))+10;

	if(!$key)
	{
		$key = '100';
	}
	
	$sub_menu[$key] = array('id' => 'myhosting_logs', 'title' => $lang->myhosting_logs, 'link' => "index.php?module=tools/myhosting_logs");
}

function myhosting_logact(&$action)
{
	$action['myhosting_logs'] = array('active' => 'myhosting_logs', 'file' => '');
}

function myhosting_logperm(&$admin_permissions)
{
  	global $db, $mybb, $lang;
	$lang->load("myhosting", true, true);
		
	$admin_permissions['myhosting_logs'] = $lang->myhosting_logs;
}

function myhosting_logs()
{
	global $mybb, $db, $page, $lang;

	if($page->active_action != "myhosting_logs")
	{
		return;
	}

	$page->add_breadcrumb_item($lang->myhosting_logs);

		$page->output_header($lang->myhosting_logs);

		$table = new Table;

		$table->construct_header($lang->myhosting_time, array("class" => "align_center","width" => "15%"));
		$table->construct_header($lang->myhosting_uid, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_msg, array("class" => "align_center", "width" => "75%"));
		$table->construct_row();

$num = intval($mybb->input['num']);
$uid = intval($mybb->input['uid']);
if (!$num) {
	$num = "10";
}
if (!$uid) {
	$query = $db->simple_select("myhostinglogs", "*", "", array('order_by' => 'logid', 'order_dir' => 'desc', 'limit' => $num));
}
else {
	$query = $db->simple_select("myhostinglogs", "*", "uid = $uid", array('order_by' => 'logid', 'order_dir' => 'desc', 'limit' => $num));
}
if ($db->num_rows($query) == 0) {
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_row();
}
else {
	while($row = $db->fetch_array($query)) {
		$table->construct_cell('<center>'.my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'],$row['time']).'</center>');
		$table->construct_cell('<center>'.$db->escape_string($row['uid']).'</center>');
		$table->construct_cell('<center>'.$db->escape_string($row['msg']).'</center>');
		$table->construct_row();
	}
}
		$table->output($lang->myhosting_admin);
		echo '<p align="right">Display: <a href="index.php?module=tools/myhosting_logs&num=25">25</a> <a href="index.php?module=tools/myhosting_logs&num=50">50</a> <a href="index.php?module=tools/myhosting_logs&num=100">100</a> <a href="index.php?module=tools/myhosting_logs&num=200">200</a> <a href="index.php?module=tools/myhosting_logs&num=500">500</a></p>';
	
	$page->output_footer();

}

function myhosting_adminnav(&$sub_menu)
{
	global $mybb, $lang;
	$lang->load("myhosting", false, true);
		
	end($sub_menu);
	$key = (key($sub_menu))+10;

	if(!$key)
	{
		$key = '100';
	}
	
	$sub_menu[$key] = array('id' => 'myhosting_admin', 'title' => $lang->myhosting_admin, 'link' => "index.php?module=config/myhosting_admin");
}

function myhosting_adminact(&$action)
{
	$action['myhosting_admin'] = array('active' => 'myhosting_admin', 'file' => '');
}

function myhosting_adminperm(&$admin_permissions)
{
  	global $db, $mybb, $lang;
	$lang->load("myhosting", true, true);
		
	$admin_permissions['myhosting_admin'] = $lang->myhosting_admin;
}

function myhosting_admin()
{
	global $mybb, $db, $page, $lang;

	if($page->active_action != "myhosting_admin")
	{
		return;
	}
	
	$page->add_breadcrumb_item($lang->myhosting_admin);

		$page->output_header($lang->myhosting_admin);

		$table = new Table;

		$table->construct_header($lang->myhosting_time, array("class" => "align_center","width" => "15%"));
		$table->construct_header($lang->myhosting_ip, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_user, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_pkg, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_domain, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_status, array("class" => "align_center", "width" => "10%"));
		$table->construct_header($lang->myhosting_action, array("class" => "align_center", "width" => "10%"));
		$table->construct_row();

$upkg = $mybb->input['upkg'];
$ustat = $mybb->input['ustat'];
$unum = $mybb->input['unum'];
$myhpkg1 = $mybb->settings['myhosting_pkg1'];
$myhpkg2 = $mybb->settings['myhosting_pkg2'];
$myhpkg3 = $mybb->settings['myhosting_pkg3'];
$stat0 = $lang->myhosting_stat0;
$stat1 = $lang->myhosting_stat1;
$stat2 = $lang->myhosting_stat2;
$stat3 = $lang->myhosting_stat3;

if (!$unum) {
	$unum = "10";
}
if ($upkg == 9) {
	$upkg = "";
}
if ($ustat == 9) {
	$ustat = "";
}

$query = $db->simple_select("myhosting", "*", "pkg LIKE '%$upkg%' AND status LIKE '%$ustat%'", array('order_by' => 'hid', 'order_dir' => 'desc', 'limit' => $unum));

if ($db->num_rows($query) == 0) {
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_cell("<center>-</center>");
		$table->construct_row();
}
else {

	while($row = $db->fetch_array($query)) {
		if ($db->escape_string($row['pkg']) == 1) {
			$usrpkg = $myhpkg1;
		}
		elseif ($db->escape_string($row['pkg']) == 2) {
			$usrpkg = $myhpkg2;
		}
		elseif ($db->escape_string($row['pkg']) == 3) {
			$usrpkg = $myhpkg3;
		}
		if ($db->escape_string($row['status']) == 0) {
			$usrstatus = $stat0;
			$usrstatact = '<a href="../myhosting.php?act=do_activate&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/approve.png" title="Approve"></a>';
			$usrsuspendact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrcancelact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrdeleteact = '<a href="../myhosting.php?act=do_delete&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/delete.png" title="Delete"></a>';
		}
		elseif ($db->escape_string($row['status']) == 1) {
			$usrstatus = $stat1;
			$usrstatact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrsuspendact = '<a href="../myhosting.php?act=do_suspend&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/suspend.png" title="Suspend"></a>';
			$usrcancelact = '<a href="../myhosting.php?act=do_cancel&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/cancel.png" title="Cancel"></a>';
			$usrdeleteact = '<a href="../myhosting.php?act=do_delete&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/delete.png" title="Delete"></a>';
		}
		elseif ($db->escape_string($row['status']) == 2) {
			$usrstatus = $stat2;
			$usrstatact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrsuspendact = '<a href="../myhosting.php?act=do_unsuspend&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/unsuspend.png" title="Unsuspend"></a>';
			$usrcancelact = '<a href="../myhosting.php?act=do_cancel&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/cancel.png" title="Cancel"></a>';
			$usrdeleteact = '<a href="../myhosting.php?act=do_delete&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/delete.png" title="Delete"></a>';
		}
		elseif ($db->escape_string($row['status']) == 3) {
			$usrstatus = $stat3;
			$usrstatact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrsuspendact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrcancelact = '<img src="../images/myhosting/noaction.png" title="No Action"></a>';
			$usrdeleteact = '<a href="../myhosting.php?act=do_delete&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/delete.png" title="Delete"></a>';
		}
		$table->construct_cell('<center>'.my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'],$row['time']).'</center>');
		$table->construct_cell('<center>'.$db->escape_string($row['regip']).'</center>');
		$table->construct_cell('<center><a href="../user-' . $db->escape_string($row['uid']) . '.html" />' . $db->escape_string($row['fusr']) . '</a></center>');
		$table->construct_cell('<center>'.$usrpkg.'</center>');
		$table->construct_cell('<center><a href="http://' . $db->escape_string($row['domain']) . '" />' . $db->escape_string($row['domain']) . '</a></center>');
		$table->construct_cell('<center>'.$usrstatus.'</center>');
		$table->construct_cell('<center><a href="../myhosting.php?act=do_show&shu=' . $db->escape_string($row['uid']) . '&my_post_key=' . $mybb->post_code. '" /><img src="../images/myhosting/view.png" title="View/Edit"></a></a>'.$usrstatact . $usrsuspendact . $usrcancelact . $usrdeleteact.'</center>');
		$table->construct_row();
	}
}
		$table->output($lang->myhosting_admin);
		$form = new Form("index.php?module=config/myhosting_admin", "post");
		echo '<p align="center">
			<select name="unum">
			<option value="10">10</option>
			<option value="25">25</option>
			<option value="50">50</option>
			<option value="100">100</option>
			<option value="200">200</option>
			<option value="500">500</option>
			</select>
			<select name="upkg">
			<option value="9">ALL</option>
			<option value="1">' . $myhpkg1 . '</option>
			<option value="2">' . $myhpkg2 . '</option>
			<option value="3">' . $myhpkg3 . '</option>
			</select>
			<select name="ustat">
			<option value="9">ALL</option>
			<option value="0">' . $stat0 . '</option>
			<option value="1">' . $stat1 . '</option>
			<option value="2">' . $stat2 . '</option>
			<option value="3">' . $stat3 . '</option>
			</select>
			<input type="submit" value="Filter" />
		      </p>';
		$form->end;

	$page->output_footer();

}

?>
